Bust UTF-8 encoded waypoint names and comments down to ASCII for Mapsend.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 16 Jan 2005 23:22:19 +0000 (23:22 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 16 Jan 2005 23:22:19 +0000 (23:22 +0000)
gpsbabel/mapsend.c

index c7e24febaff68585b4ce9180d5759a172297479e..1bf106af7efc409560e8996f9055ead92c82263e 100644 (file)
@@ -318,19 +318,41 @@ mapsend_waypt_pr(const waypoint *waypointp)
        const char *sn = global_opts.synthesize_shortnames ? 
                mkshort(mkshort_handle, waypointp->description) :
                waypointp->shortname;
+       char *tmp;
 
-       c = sn ? strlen(sn) : 0;
+       /*
+        * The format spec doesn't call out the character set of waypoint
+        * name and description.  Empirically, we can see that it's 8859-1,
+        * but if we create mapsend files containing those, Mapsend becomes
+        * grumpy uploading the resulting waypoints and being unable to deal
+        * with the resulting comm errors.
+        * 
+        * Ironically, our own Magellan serial module strips the "naughty"
+        * characters, keeping it more in definition with their own serial
+        * spec. :-)
+        * 
+        * So we just decompose the utf8 strings to ascii before stuffing
+        * them into the Mapsend file.
+        */
+
+       tmp = str_utf8_to_ascii(sn);
+       c = tmp ? strlen(tmp) : 0;
        fwrite(&c, 1, 1, mapsend_file_out);
-       fwrite(sn, c, 1, mapsend_file_out);
+       fwrite(tmp, c, 1, mapsend_file_out);
+       if (tmp)
+               xfree(tmp);
 
-       if (waypointp->description) 
-               c = strlen(waypointp->description);
+       tmp = str_utf8_to_ascii(waypointp->description);
+       if (tmp)
+               c = strlen(tmp);
        else
                c = 0;
 
        if (c > 30) c = 30;
        fwrite(&c, 1, 1, mapsend_file_out);
-       fwrite(waypointp->description, c, 1, mapsend_file_out);
+       fwrite(tmp, c, 1, mapsend_file_out);
+       if (tmp)
+               xfree(tmp);
 
        /* #, icon, status */
        n = ++cnt;